/*
 * Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhongketech.sunflower.transport.gentest;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

/**
 * Generates entities and DAOs for the example project DaoExample.
 * 
 * Run it as a Java application (not Android).
 * 
 * @author Markus
 */
public class ZkDaoGenerator {

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(1, "com.zhongketech.sunflower.transport.model");

        addSmsCode(schema);
        addUsers(schema);
        addRequest(schema);
        addContact(schema);

        new DaoGenerator().generateAll(schema, "../Transport/src");
    }
    
    private static void addSmsCode(Schema schema) {
        Entity smsCode = schema.addEntity("SmsCode");
        smsCode.addIdProperty();
        smsCode.addStringProperty("smscode").notNull();
    }
    
    private static void addContact(Schema schema)
    {
    	Entity contactInfo = schema.addEntity("Contact");
    	contactInfo.addStringProperty("id");
		contactInfo.addStringProperty("group");
		contactInfo.addStringProperty("contactId");
		contactInfo.addStringProperty("visible_id");
		contactInfo.addStringProperty("name");
		contactInfo.addStringProperty("role");
		contactInfo.addStringProperty("gender");
		contactInfo.addStringProperty("birthday");
		contactInfo.addStringProperty("phone");
		contactInfo.addStringProperty("avatar_url");
//		Property userId = contactInfo.addStringProperty("userId").notNull()
//				.getProperty();
//		contactInfo.addToOne(userInfo, userId);
//		userInfo.addToMany(contactInfo, userId);
    }
    
    private static void addRequest(Schema schema)
    {
    	Entity requestInfo = schema.addEntity("Request");
		requestInfo.addStringProperty("id");
		requestInfo.addStringProperty("type");
		requestInfo.addStringProperty("from");
		requestInfo.addStringProperty("to");
		requestInfo.addStringProperty("create_at");
		requestInfo.addStringProperty("text");
		requestInfo.addStringProperty("state");
//		Property mastId = requestInfo.addStringProperty("masterId")
//				.primaryKey().notNull().getProperty();
//		requestInfo.addToOne(userInfo, mastId);
//		userInfo.addToMany(requestInfo, mastId);
    }
    
    
    private static void addUsers(Schema schema) {
    	
		/*-------------------- User part -------------------------*/
		Entity userInfo = schema.addEntity("User");
		Property userFk = userInfo.addStringProperty("id").primaryKey()
				.getProperty();
		userInfo.addStringProperty("visible_id");

		userInfo.addStringProperty("role"); 
		userInfo.addStringProperty("phone"); 
		userInfo.addStringProperty("password");
		userInfo.addStringProperty("gender");
		userInfo.addStringProperty("name"); 
		userInfo.addStringProperty("birthday"); 
		userInfo.addStringProperty("avatar_url"); 
		
		Entity schoolInfo = schema.addEntity("School");
		schoolInfo.addStringProperty("schoolId");
		schoolInfo.addStringProperty("school_name");
		schoolInfo.addStringProperty("userKey").notNull().primaryKey();
		userInfo.addToOne(schoolInfo, userFk);
		
		Entity classInfo = schema.addEntity("Classes");
		classInfo.addStringProperty("id");
		classInfo.addStringProperty("classes");
		classInfo.addStringProperty("grade");
		classInfo.addStringProperty("userkey").primaryKey();
		userInfo.addToOne(classInfo, userFk);
    }


 
}
